package com.airface.eureka.locator;

import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy;
import org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

/**
 * @author flw
 * @version 2.0
 * @Description
 * @date 2019/1/29
 */
@Configuration
public class CustomPropertySourceLocator implements PropertySourceLocator {
    @Override
    public PropertySource<?> locate(Environment environment) {
        try {
            PropertySource propertySource = new ResourcePropertySource(new ClassPathResource("bootstrap-dev.yml"));
            return propertySource;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Bean
    LoadBalancedRetryFactory retryFactory() {
        return new LoadBalancedRetryFactory() {
            @Override
            public LoadBalancedRetryPolicy createRetryPolicy(String service, ServiceInstanceChooser serviceInstanceChooser) {
                return null;
            }
        };
    }
}
